<template>
  <template v-if="!menu.meta?.hidden">
    <el-submenu v-if="menu.children" :index="menu.path" popper-class="sider-submenu">
      <template #title>
        <i v-if="hasIcon && menu.meta?.icon" :class="menu.meta.icon"></i>
        <span>{{ menu.meta?.title }}</span>
      </template>
      <side-menu-item
        v-for="item in menu.children"
        :key="item.path"
        :menu="item"
        :hasIcon="false"
      ></side-menu-item>
    </el-submenu>
    <el-menu-item v-else :index="menu.path">
      <i v-if="hasIcon && menu.meta?.icon" :class="menu.meta.icon"></i>
      <template #title>
        {{ menu.meta?.title }}
      </template>
    </el-menu-item>
  </template>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'SideMenuItem',
  props: {
    menu: {
      type: Object,
      required: true
    },
    hasIcon: {
      type: Boolean,
      default: true
    }
  }
})
</script>

<style lang="scss" scoped>
:deep(.el-submenu__title) {
  height: 48px;
  line-height: 48px;
}

:deep(.el-submenu .el-menu-item) {
  height: 44px;
  line-height: 44px;
}

:deep(.el-menu-item) {
  height: 44px;
  line-height: 44px;
}
</style>

<style lang="scss">
@import '@/styles/vars.scss';

.is-active > .el-submenu__title {
  color: $subMenuActiveText !important;

  i {
    color: $subMenuActiveText;
  }
}

.sider-submenu {
  .el-submenu__title {
    height: 48px;
    line-height: 48px;
  }

  .el-submenu .el-menu-item {
    height: 44px;
    line-height: 44px;
  }
}

.sider-menus {
  .el-menu-item {
    height: 44px;
    line-height: 44px;
  }
}
</style>
